<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="page_right combopage_right">
    <ul class="combo_addlist"></ul>
    <div><a class="combo_addbtn" href="javascript:;"><span style="font-size:24px;">+</span> 添加</a></div>
</div>

<!-- 添加套餐 提示弹窗 -->
<div class="pointpage_dv1">
    <div class="pointpage1">
        <p class="pointpage_beginpsd">套餐添加成功！</p>
    </div>
</div>
<!-- 添加套餐 提示弹窗 end -->
<script type="application/javascript">

    var reg_name = /^\s*$/;

    //添加套餐
    $(".combo_addbtn").on("click", function(){
        $(this).parent().prev("ul").append("<li><i>"+($(".combo_addlist li").length+1)+"</i>" +
            "<span>套餐单价：</span><input type='number' value='1'>" +
            "<span>套餐币数：</span><input class='combo_add_combonumber' type='number' value='1'>" +
            "<span>套餐名称：</span><input type='text' class='combo_add_name'>" +
            "<a class='combo_addbutton' href='javascript:;'>确认</a>" +
            "<a class='combo_addcancel' href='javascript:;'>取消</a></li>");

        //添加币数输入框
        $(".combo_add_combonumber").on("keyup", function(){
            var combo_add_numbvalue0=parseInt($(this).val());
            if(combo_add_numbvalue0>999){
                combo_add_numbvalue0=999;
            }
            $(this).val(combo_add_numbvalue0);
            if(combo_add_numbvalue0<=0){
                $(this).css("box-shadow","0 0 3px 1px #f00");
            }else{
                $(this).css("box-shadow","none");
            }
        });

        //添加确认
        $(".combo_addbutton").on("click", function(){
            var combo_add_moneyvalue=$(this).closest("li").find("input:eq(0)").val();
            var combo_add_numbvalue=parseInt($(this).closest("li").find("input:eq(1)").val());
            var combo_name=$(this).closest("li").find("input:eq(2)").val();
            if(combo_add_numbvalue>999){
                combo_add_numbvalue=999;
            }
            $(this).closest("li").find("input:eq(1)").val(combo_add_numbvalue);
            if(combo_add_moneyvalue<=0){
                $(this).closest("li").find("input:eq(0)").css("box-shadow","0 0 3px 1px #f00");

            }else if(combo_add_moneyvalue>0 && combo_add_numbvalue<=0){
                $(this).closest("li").find("input:eq(0)").css("box-shadow","none");
                $(this).closest("li").find("input:eq(1)").css("box-shadow","0 0 3px 1px #f00");

            }else if(combo_add_numbvalue>0 && combo_add_moneyvalue>0){
                $(this).closest("li").find("input:eq(1)").css("box-shadow","none");
                $(this).closest("li").find("input:eq(0)").css("box-shadow","none");
                $(this).parent().remove();
            }else if(reg_name.test(combo_name)){
                console.log(1111);
            }

            console.log(combo_add_moneyvalue+"-->"+combo_add_numbvalue+"-->"+combo_name);

            //addCombo(combo_add_moneyvalue,combo_add_numbvalue,combo_name);
        });
        //添加取消
        $(".combo_addcancel").on("click", function(){
            $(this).parent().remove();
        })
    });

    function addCombo(m,n,o){
        var money = eval(m);
        var coin = eval(n);
        var name = o;
        $.ajax({
            url:'${basePath}v2/combo/addCombo',
            type : 'POST',
            data : {"money":money,"coin":coin,"discountName":name},
            success: function (ret) {
                if(ret.result==false) {
                    alert(ret.info);
                }
            }
        });
    }
</script>